<template>
  <div class="returnCode-content">
    <Row>
      <Col span="4" class="panel-search-code"><Input placeholder="设备编号" v-model="queryObj.deviceCode"/></Col>
      <Col span="4" class="panel-search-ip"><Input placeholder="IP" v-model="queryObj.ip"/></Col>
      <Col span="4" class="panel-search-returnCode"><Input placeholder="错误代码" v-model="queryObj.returnCode"/></Col>
      <Col span="4"><Button type="primary" @click="handleSearch()">查询</Button></Col>
    </Row>

    <div class="panel-count">共 <span class="count-number">{{this.total.toLocaleString()}}</span> 条数据({{this.spendTime}} 秒)</div>
    <Card>
      <tables :loading="loading" stripe ref="tables" v-model="tableData" :columns="columns"/>
      <Page class="panel-page" :total="total" :current="page" :page-size="size" @on-change="changePage" show-elevator />
    </Card>
  </div>
</template>

<script>
import Tables from '_c/tables'
import { apiSearch } from '@/api/returnCode'
export default {
  name: 'ReturnCode',
  components: {
    Tables
  },
  data () {
    return {
      columns: [
        { title: '设备类型', key: 'deviceType', sortable: false },
        { title: '设备编号', key: 'deviceCode', sortable: false },
        { title: 'IP', key: 'ip', sortable: false },
        { title: '错误代码', key: 'returnCode', sortable: false, width: 90 },
        { title: '错误信息', key: 'errorMsg', sortable: false, tooltip: true },
        { title: '总次数', key: 'totalCount', sortable: false, width: 80 },
        { title: '周期次数', key: 'cycleCount', sortable: false, width: 60 },
        { title: '能否重复', key: 'status', sortable: false, width: 60 },
        { title: '黑名单次数', key: 'blacklistCount', sortable: false, width: 80 },
        { title: '创建时间', key: 'createTime', width: 90 },
        { title: '修改时间', key: 'updateTime', sortable: true, width: 150 }
      ],
      tableData: [],
      page: 1,
      size: 10,
      total: 0,
      spendTime: 0,
      queryObj: {
        ip: '',
        deviceCode: '',
        returnCode: ''
      },
      loading: false
    }
  },
  methods: {
    // 获取数据
    getData () {
      this.loading = true
      const param = JSON.stringify(this.queryObj)
      apiSearch(this.page, param).then(res => {
        const code = res.data.code
        // console.log(res.data)
        if (code === 0) {
          this.total = res.data.data.total
          this.page = res.data.data.page
          this.spendTime = res.data.data.spendTime
          this.tableData = res.data.data.content
          this.loading = false
        } else {
          this.$Message.error(res.data.msg)
        }
      })
    },
    // 点击页码
    changePage (page) {
      this.page = page
      this.getData()
    },
    handleSearch () {
      this.page = 1
      this.getData()
    }
  },
  mounted () {
    this.page = 1
    this.getData()
  }
}
</script>

<style lang="less">
  @import "./ReturnCode";
</style>
